package com.lais.record.base.advice;

import com.lais.record.common.exception.RecordExceptionAdvice;
import com.lais.record.common.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import static com.lais.record.base.constant.RecordBaseEnum.PARAM_ERROR;

/**
 * @Author: luowen
 * @Description:
 * @Date: Create in 18:01 2019/11/30
 */
@RestControllerAdvice
@Slf4j
public class BaseExceptionAdvice extends RecordExceptionAdvice {

    @ExceptionHandler(HttpMessageNotReadableException.class)
    public Result handlerHttpMessageNotReadableException(HttpMessageNotReadableException exec){
        log.error("全局自定义异常---异常信息为：{}",exec);
        Result<Object> result = new Result<>();
        result.setFlag(false);
        result.setCode(PARAM_ERROR.getCode());
        result.setMessage(PARAM_ERROR.getMessage());
        return result;
    }
}
